import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { getJqrlfx } from '@gis/lib/api';

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = 'cyjq';
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getIconOption(icon) {
    return {
      content: `<div style="width: 52px;height: 96px;background: url(${icon}) center center no-repeat;background-size: 100% 100%"></div>`,
      offset: new AMap.Pixel(0, 0),
    };
  }
  onClick() {}
}

export default class Cyjq extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const data = await handleCommonRes(getJqrlfx, { area_code: area_code });
    return data.map((item) => {
      return Object.assign(item, { lnglat: [item.lng, item.lat], longitude: item.lng, latitude: item.lat });
    });
  }
}
